package com.mine.main;

import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.mine.control.ControlTable;
import com.mine.util.FormatReport;
import com.mine.util.OutputReport;
import com.mine.util.SearchFile;

public class DiffOfReport {
	public static void diffReport(String path, String tableName, String outputPath, String type) throws Exception {
		ArrayList<String[]> al = FormatReport
				.formatReport(path, type);
		StringBuffer sb = new StringBuffer();
		int i = 0;
		System.out.println(al.size());
		for (String[] result : al) {
			ResultSet rs = ControlTable.selectTargetTable(tableName, result[0]);
			String dalvikResult = rs.getString(3);
			String time = rs.getString(4);
			if(!dalvikResult.equals(result[1])){
				sb.append("Diff "+(i++)+" Case :"+ "\n");
				sb.append(result[0]+ "\n");
				sb.append("Dalvik Result:"+dalvikResult+", cast time: "+time+"\n");
				sb.append("Vmkid  Result:"+result[1]+", cast time: "+result[2]+"\n");
				sb.append("\n");
			}
		}
		if(i==0)sb.append("Have same result!");
		OutputReport.f = new File(outputPath);
		OutputReport.outputFile(sb);
	}
//	public static void main(String[] args) throws Exception{
//		//init dalvik api result DataBase
//		String tagPath = "F:\\JCK\\K-Touch\\dalvik\\api.xml";
//		String tagTable = "dalvik_jck_api_report";
//		InitDatebase.initDataBase(tagPath, tagTable);
//		
//		//init dalvik lang result DataBase
//		String tagPath1 = "F:\\JCK\\K-Touch\\dalvik\\lang.xml";
//		String tagTable1 = "dalvik_jck_lang_report";
//		InitDatebase.initDataBase(tagPath1, tagTable1);
//		
//		//init dalvik stress result DateBase
//		String tagDir = "F:\\Stress\\K-Touch\\dalvik\\KTouch_DALVIKVM_NOJIT�汾_150s";
//		String tagTable2 = "dalvik_stress_report";
//		ArrayList<String> array = SearchFile.readDir(tagDir);
//		for(String filepath : array){
//			
//		}
//		
//		String path = "F:\\testAllapi_1.11.5_new.xml";
//		String tableName = "dalvik_jck_api_report";
//		String outputPath = "F:\\api_diff.txt";
//		DiffOfReport.diffReport(path, tableName, outputPath);
//		
//		String path1 = "F:\\testAlllang_1.11.5_new.xml";
//		String tableName1 = "dalvik_jck_lang_report";
//		String outputPath1 = "F:\\lang_diff.txt";
//		DiffOfReport.diffReport(path1, tableName1, outputPath1);
//	}
}
